package com.zero2oneblog.controller;

import com.zero2oneblog.queue.ArticlePublisher;
import com.zero2oneblog.queue.UserSubscriber;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
//@RequestMapping("/public/users")
public class RabbitMQController {
    @Autowired
    private ArticlePublisher articlePublisher;

    @Autowired
    private UserSubscriber userSubscriber;

    @PostMapping("/public/subscribe")
    public String subscribe(@RequestParam String author, @RequestParam String username) {
        userSubscriber.subscribe(author, username);
        return "Subscribed successfully!";
    }

    @PostMapping("/public/publish")
    public String publishArticle(@RequestParam String author, @RequestParam String article) {
        articlePublisher.publishArticle(author, article);
        return "Article published successfully!";
    }
}
